package com.sangmo.fts.training.model;

import com.sangmo.boot.framework.data.constraint.meta.Unique;
import com.sangmo.boot.framework.data.entity.general.LongEntity2;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.process.factoring.model.FfLoan;
import com.sangmo.fts.user.model.User;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Entity
@Table(name = "teammate")
@DataView
@ExtView
public class Teammate extends LongEntity2 {

//    @One(value = "team", target = Team.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long teamId;

    @Unique(with = {"teamId"})
    @One(value = "user", target = User.class, fieldset = {"id", "name"},groups = {"default","Team.detail","Team.search"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long userId;

    private String role;

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Long getTeamId() {
        return teamId;
    }

    public void setTeamId(Long teamId) {
        this.teamId = teamId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public interface Roles {
        String BUYER = "BUYER"; //买方
        String SELLER = "SELLER"; //卖方
        String STORAGE = "STORAGE"; //物流仓储业
        String BANK = "BANK"; //银行
    }

    public static final List<String> IfTeammateRoles = new ArrayList<String>(){{
        add(Roles.SELLER);
        add(Roles.STORAGE);
        add(Roles.BANK);
    }};

    public static final List<String> CsfTeammateRoles = new ArrayList<String>(){{
        add(Roles.SELLER);
        add(Roles.STORAGE);
        add(Roles.BANK);
        add(Roles.BUYER);
    }};

    public static final List<String> RpfTeammateRoles = new ArrayList<String>(){{
        add(Roles.SELLER);
        add(Roles.BUYER);
        add(Roles.BANK);
    }};

    public static final List<String> FfTeammateRoles = new ArrayList<String>(){{
        add(Roles.SELLER);
        add(Roles.BANK);
        add(Roles.BUYER);
    }};

    public static final Map<String, List<String>> businessTypeMapRoles = new HashMap<String, List<String>>() {{
        put(Team.BusinessTypes.INVENTORY_FINANCING, IfTeammateRoles);
        put(Team.BusinessTypes.CONFIRMING_STORAGE_FINANCING, CsfTeammateRoles);
        put(Team.BusinessTypes.RECEIVABLE_PLEDGE_FINANCING, RpfTeammateRoles);
        put(Team.BusinessTypes.FACTORING_FINANCING, FfTeammateRoles);
    }};



}
